package com.lagou.servlet;

import javax.servlet.ServletException;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.net.URLDecoder;

public class GetServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // 1、通过request对象，获取到携带的所有cookie
        Cookie[] cookies = req.getCookies();

        // 2、遍历数组
        if (cookies != null ){
            for (Cookie cookie : cookies
                 ) {
                // 获取的就是cookie的name值
                String name = cookie.getName();
                // 获取cookie的value值
                String value = cookie.getValue();
                String decodevalue = URLDecoder.decode(value, "UTF-8");

                System.out.println(name + "----" + decodevalue);;

            }
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
